package com.yootk.task;

import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ShedLock分布式定时任务
 */
@Slf4j
//@Component
public class ShedLockTask {

    // 每2秒触发一次任务
    @Scheduled(cron = "*/2 * * * * ?")
    @SchedulerLock(name = "yootk-task", lockAtLeastFor = "5000")
    public void task() {    // CRON任务
        log.info("【ShedLock任务】{}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
    }
}
